<?php


namespace App\Controller\Api\Product;


use App\Controller\AbstractController;
use App\Middleware\GetAuthTokenMiddleware;
use App\Service\Product\ProductService;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Middleware;
use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\FormData;
use Yj\Apidog\Annotation\PostApi;

/**
 * @ApiController(tag="产品",prefix="api/product",description="")
 */
class Product extends AbstractController
{
    /**
     * @Inject()
     * @var ProductService
     */
    protected $productService;

    /**
     * @PostApi(path="detail", description="获取用户信息")
     * @FormData(key="id|id", rule="required")
     */
    public function detail()
    {
        $data = $this->getValidatorData();
        $datail = $this->productService->detail(['id' => $data['id']]);
        succ($datail);
    }

    /**
     * @PostApi(path="new", description="获取用户信息")
     */
    public function new()
    {
        $list = $this->productService
            ->where()
            ->with('image')
            ->orderBy('create_time', 'desc')
            ->limit(10)
            ->get();
        succ($list);
    }


    /**
     * @Middleware(GetAuthTokenMiddleware::class)
     * @PostApi(path="lists", description="获取用户信息")
     * @FormData(key="keywords", rule="nullable")
     * @FormData(key="cid",default=0)
     */
    public function lists()
    {
        $params = $this->getParams();
        $params->put('is_show', 1);
        $params->put('user_id', $this->getUid(false));
        $list = $this->productService->list($params);
        succ($list);
    }

    /**
     * @Middleware(GetAuthTokenMiddleware::class)
     * @PostApi(path="mubiao", description="获取用户信息")
     * @FormData(key="keywords", rule="nullable")
     * @FormData(key="sort_key", rule="nullable")
     * @FormData(key="sort_direction", rule="nullable")
     * @FormData(key="cid",default=0)
     */
    public function mubiao()
    {
        $params = $this->getParams();
        $params->put('is_show', 1);
        $params->put('mubiao', 1);
        $params->put('user_id', $this->getUid(false));

        $list = $this->productService->mubiao($params);
        succ($list);
    }


}